<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>名师课程列表</title>
<%@ include file="/base/jsp/include.jsp"%>
</head>
<body>
	<div class="mini-toolbar" style="padding:2px;border-bottom:0;">
		<table style="width:100%;">
			<tr>
				<td style="width:100%;"><a class="mini-button"
					iconCls="icon-upgrade" plain="true" href="javascript:updateInfo()">更新名师课程</a>
					<span class="separator"></span> <a class="mini-button"
					iconCls="icon-edit" plain="true" onclick="edit()">修改显示名称</a>
					<span class="separator"></span> <a class="mini-button"
					iconCls="icon-remove" plain="true" onclick="del()">删除</a><span
					class="separator"></span> <a class="mini-button"
					iconCls="icon-remove" plain="true" onclick="delAll()">彻底删除</a>
					<span class="separator"></span><a class="mini-button"
					iconCls="icon-cancel" plain="true" href="javascript:clearFilter()">清除筛选</a>
					<span class="separator"></span><a class="mini-button"
					iconCls="icon-upgrade" plain="true" href="javascript:addNewMessage()">添加小红点</a></td>
			</tr>
		</table>
	</div>
	<span id="module-name" style="display:none;">subject</span>
	<!--撑满页面-->
	<div class="mini-fit">
		<div id="grid" class="mini-datagrid" style="width:100%;height:100%;"
			pageSize="20" borderStyle="border:1;" url="listEssence.do" idField="id"
			multiSelect="true" showFilterRow="true">
			<div property="columns">
				<div type="checkcolumn" field="activityId"></div>
				<div type="indexcolumn" headerAlign="center">序号</div>
				<div field="displayName" width="50" headerAlign="center" align="center">标题
				<input id="titleFilter" property="filter" class="mini-textbox" style="width:100%;" onvaluechanged="onFilterChanged"/>
                </div>
                <div field="subType" width="50" headerAlign="center" align="center" renderer="subjectsHandler">科目
				<input id="subTypeFilter" property="filter" class="mini-combobox" textField="text" valueField="id" emptyText="科目"
                        url="${path}/base/subjectForNote.json" allowInput="false" showNullItem="true" nullItemText="请选择..." onvaluechanged="onFilterChanged"/></div>
                        
                 <div field="author" width="50" headerAlign="center" align="center">名师
                 <input id="authorFilter" property="filter" class="mini-combobox" textField="name" valueField="id" emptyText="名师"
                        url="getEssenceAuthors.do?type=1" allowInput="false" showNullItem="true" nullItemText="请选择..." onvaluechanged="onFilterChanged"/></div>
                <div field="browseTimes" width="50" headerAlign="center" align="center">浏览次数</div>
                <div field="isOver" width="100" headerAlign="center" align="center" renderer="overStatusControlHandler">是否结束
				<input id="overFilter" property="filter" class="mini-combobox" textField="text" valueField="id" emptyText="是否结束"
                        url="${path}/base/json/whether.json" allowInput="false" showNullItem="true" nullItemText="请选择..." onvaluechanged="onFilterChanged"/></div>
                <div field="isLocked" width="100" headerAlign="center" align="center" renderer="lockControlHandler">锁操作
				<input id="lockFilter" property="filter" class="mini-combobox" textField="text" valueField="id" emptyText="是否加锁"
                        url="${path}/base/json/whether.json" allowInput="false" showNullItem="true" nullItemText="请选择..." onvaluechanged="onFilterChanged"/></div>
				<div field="top" width="50" headerAlign="center" align="center" renderer="orderControlHandler">操作</div>
                
		</div>
	</div>
	<script type="text/javascript">
	mini.parse();
	var grid = mini.get("grid");
	grid.load();	
	var rssData;
	function addRow() {
		mini.open({
			url : "toEditEssenceCourse.do",
			title : "添加具体名师班级",
			width : editorWinWidth,
			height : editorWinHeight,
			showMaxButton: Boolean,     //显示最大化按钮
			onload : function() {
				var iframe = this.getIFrameEl();
				var data = {
					action : "new"
				};
				iframe.contentWindow.SetData(data);
			},
			ondestroy : function(action) {
				grid.reload();
			}
		});
	}
	


	function del() {
		var rows = grid.getSelecteds();
		if (rows.length > 0) {
			mini.confirm("确定删除吗？", "确定？", function(action) {
				if (action == "ok") {
					var ids = [];
					for ( var i = 0, l = rows.length; i < l; i++) {
						var r = rows[i];
						ids.push(r.id);
					}
					var id = ids.join(",");
					grid.loading("操作中，请稍后......");
					$.ajax({
						url : "delEssence.do?id=" + id+"&type=0",
						success : function(text) {
							if(text.indexOf("true") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
						},
						error : function() {
						}
					});
				}
			});
		} else {
			mini.alert("请选中一条记录");
		}
	}
	
	function delAll() {
		var rows = grid.getSelecteds();
		if (rows.length > 0) {
			mini.confirm("完全删除将会清除所有的文件？", "确定？", function(action) {
				if (action == "ok") {
					var ids = [];
					for ( var i = 0, l = rows.length; i < l; i++) {
						var r = rows[i];
						ids.push(r.id);
					}
					var id = ids.join(",");
					grid.loading("操作中，请稍后......");
					$.ajax({
						url : "delEssence.do?id=" + id+"&type=1",
						success : function(text) {
							if(text.indexOf("true") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
						},
						error : function() {
						}
					});
				}
			});
		} else {
			mini.alert("请选中一条记录");
		}
	}
	


	function edit() {
		var rows = grid.getSelecteds();
		if (rows.length == 1) {
			var row = grid.getSelected();
			mini.open({
				url : "toEditEssence.do",
				title : "名师班级编辑",
				width : editorWinWidth,
				height : editorWinHeight,
				showMaxButton: true,     //显示最大化按钮
				onload : function() {
					var iframe = this.getIFrameEl();
					var data = {
						action : "edit",
						id : row.id
					};
					iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
					grid.reload();
				}
			});
		} else if (rows.length > 1) {
			mini.alert("只能选一条记录");
		} else {
			mini.alert("请选中一条记录");
		}
	}


	function moveUp(uid) {
        	$.ajax({
                    	url: "moveUpEssence.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("true") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("上移失败");
                    	}
                	});
        }
    function moveDown(uid) {
        	$.ajax({
                    	url: "moveDownEssence.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
                	});
      }
      
      function cancelLock(uid){
     	$.ajax({
                    	url: "cancelEssenceLock.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
                	});
     }
     
     function addLock(uid){
     	$.ajax({
                    	url: "addEssenceLock.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
                	});
     }
     
      function addLockAbsolute(uid){
     	$.ajax({
                    	url: "addEssenceLockAbsolute.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
                	});
     }
     
   function cancelOver(uid){
       $.ajax({
                    	url: "cancelEssenceOver.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
         });
   }
   
   function addOver(uid){
   $.ajax({
                    	url: "addEssenceOver.do?id=" + uid,
                    	cache: false,
                    	success: function (text) {
                    		if(text.indexOf("success") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("下移失败");
                    	}
         });
   }
   
    function addNewMessage(){
     	mini.confirm("确定添加吗？", "确定？", function(action) {
				if (action == "ok") {
					$.ajax({
						url : "addEssenceNewMessage.do",
						success : function(text) {
							if(text.indexOf("true") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
						},
						error : function() {
						}
					});
				}
			});
     }
   
   function updateInfo(){
           mini.confirm("确定更新资源吗？", "确定？", function(action) {
				if (action == "ok") {
				     grid.loading("操作中，请稍后......");
					 $.ajax({
                    	url: "updateEssence.do",
                    	cache: false,
                    	timeout:300000,
                    	success: function (text) {
                    		if(text.indexOf("true") > -1){
                    			mini.alert("操作成功");
                    		}else{
                    			mini.alert("操作失败");
                    		}
                    		onFilterChanged();
                   		},
                   		error: function (jqXHR, textStatus, errorThrown) {
                   			mini.alert("操作失败");
                    	}
                	});
				}
		   });
   }
       
       
   function onFilterChanged() {
       var title = mini.get("titleFilter").getFormValue();
       var author = mini.get("authorFilter").getFormValue();
       var subType = mini.get("subTypeFilter").getFormValue();
       var isOver = mini.get("overFilter").getFormValue();
       var isLocked = mini.get("lockFilter").getFormValue();
       grid.load({title : title,author:author,subType:subType,isOver:isOver,isLocked:isLocked});
   }
	
	function clearFilter() {
	   mini.get("titleFilter").setValue("");
	   mini.get("authorFilter").setValue("");
	   mini.get("subTypeFilter").setValue("");
	   mini.get("overFilter").setValue("");
	   mini.get("lockFilter").setValue("");
       grid.load();
   }
</script>
</body>

</html>
